$(function () {
    if(localStorage.getItem("check")!=null){
        $(".l_user").val(localStorage.getItem("loginName"));
        $(".l_pwd").val(localStorage.getItem("passWord"));
        $("form [type='checkbox']")[0].checked=true;
    }
    $(".log_btn").click(function () {
        var che=$("form [type='checkbox']")[0];
        var loginName=$(".l_user").val();
        var passWord=$(".l_pwd").val();
        $.ajax({
            url:"easybuy/login",
            type:"post",
            data:{
                loginName:loginName,
                passWord:passWord
            },
            dataType:"json",
            success:function (data) {
                if(data.state==1){
                    alert("用户不存在！")
                }else if(data.state==2){
                    alert("密码错误！")
                }else if(data.state==3){
                    alert("登录成功！");
                    localStorage.setItem("user",JSON.stringify(data.user));
                    if(che.checked){
                        localStorage.setItem("loginName",loginName);
                        localStorage.setItem("passWord",passWord);
                        localStorage.setItem("check",true);
                    }else{
                        localStorage.removeItem("loginName");
                        localStorage.removeItem("passWord");
                        localStorage.removeItem("check");
                    }
                    //console.log(JSON.parse(localStorage.getItem("user")));
                    location.href="Index.html";
                }
            }
        });
    });
})